<script type="text/javascript">
jQuery(document).ready(function(){
	jQuery('.customselect').customSelect();
	jQuery(".position_main").height(jQuery(window).height());
	jQuery('.content_text').slimScroll({
		height:'530px',
		railVisible: true,
		color:'#646673',
		size:'12px',
		railOpacity: 1,
		alwaysVisible: true
	});
	jQuery( "#datepicker" ).datepicker({ dateFormat: 'dd-mm-yy' });
});
</script>
<script type="text/javascript" charset="utf-8">
	function findArea()
	{
		var city = $(".current_city").val();
		$.ajax({
			url: '<?php echo Yii::app()->createUrl("news/getarea"); ?>',
			type: 'POST',
			data: {id: city},
			success: function(response){
				var area = $.parseJSON(response);
				// var count = area.length;
				$('select.current_district').children().remove();
				$('select.current_district').append("<option value='none'>Quận / Huyện</option>");
				$.each(area,function(msg, jsonObj){

					$('.current_district').append("<option value='"+ jsonObj.id +"'>" + jsonObj.name + "</option>");
				});			
			},
			error: function(){
				alert('Hệ thống bị nghẽn, vui lòng thử lại sau');
			}
		})
	}
</script>
<script type="text/javascript" charset="utf-8">
	function findAreaFuture()
	{
		var city = $(".future_city").val();
		$('select.future_district').children().remove();
		$('select.future_district').append("<option selected>Quận / Huyện</option>");
		$.ajax({
			url: '<?php echo Yii::app()->createUrl("news/getarea"); ?>',
			type: 'POST',
			data: {id: city},
			success: function(response){
				var area = $.parseJSON(response);
				// var count = area.length;
				
				$.each(area,function(msg, jsonObj){
					
					$('.future_district').append("<option value='"+ jsonObj.id +"'>" + jsonObj.name + "</option>");
				});			
			},
			error: function(){
				alert('Hệ thống bị nghẽn, vui lòng thử lại sau');
			}
		})
	}
</script>
<script type="text/javascript" charset="utf-8">
	function findDistFuture()
	{
		var dist = $(".future_district").val();
		$.ajax({
			url: '<?php echo Yii::app()->createUrl("news/getarea"); ?>',
			type: 'POST',
			data: {dist: dist},
			success: function(response){
				var area = $.parseJSON(response);
				$('select.future_ward').children().remove();
				$('select.future_ward').append("<option value='none'>Phường /Xã</option>");
				// var count = area.length;
				$.each(area,function(msg, jsonObj){
					$('.future_ward').append("<option value='"+ jsonObj.name +"'>" + jsonObj.name + "</option>");
				});			
			},
			error: function(){
				alert('Hệ thống bị nghẽn, vui lòng thử lại sau');
			}
		})
	}
</script>
<div class="content">
	<div class="content_text">
		<h2>
			Đăng Tin
		</h2>
		<?php if(isset($msg)) : ?>
		<label style="color:red;font-weight:bold;"><?php echo $msg; ?></label>
	<?php else :?>


	<form class="content_form post_news" id="form_post_news" action="<?php echo Yii::app()->createUrl('news/create');?>" method="POST">
		<label>Nơi bạn đang cư trú/Chỗ ở hiện tại</label>
		<p class="input_wrapper fl"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/front/images/icon_location_01.png" /><select onchange="findArea();" class="customselect current_city" name="News[current_city]">
				<option value="none">Tỉnh/thành</option>
				<?php if(isset($city)): ?>
					<?php foreach($city as $value) : ?>
						<option value="<?php echo $value['id']; ?>"><?php echo $value['name'];  ?></option>
					<?php endforeach; ?>
				<?php endif; ?>
			</select>
		</p>
		<p class="input_wrapper fl"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/front/images/icon_location_02.png" /><select class="customselect current_district" name="News[current_district]">
				<option value="none">Quận / Huyện</option>
				
			</select>
		</p>
		<div class="clear"></div>
		<label>Nơi bạn sắp đi đến</label>
		<p class="input_wrapper fl"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/front/images/icon_location_01.png" /><select class="customselect future_city" onchange="findAreaFuture();" name="News[future_city]">
				<option value="none">Tỉnh/thành</option>
				<?php if(isset($city)): ?>
					<?php foreach($city as $value) : ?>
						<option value="<?php echo $value['id']; ?>"><?php echo $value['name'];  ?></option>
					<?php endforeach; ?>
				<?php endif; ?>
			</select></p>
			<p class="input_wrapper fl"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/front/images/icon_location_02.png" /><select onchange="findDistFuture();" class="customselect future_district" name="News[future_district]">
					<option value="none">Quận / Huyện</option>
				</select></p>
				<p class="input_wrapper fl"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/front/images/icon_location_03.png" /><select class="customselect future_ward" name="News[future_ward]">
						<option value="none">Phường/Xã</option>
					</select></p>
					<div class="clear"></div>
					<label>Ngày khởi hành</label>
					<p class="input_wrapper">
						<img src="<?php echo Yii::app()->theme->baseUrl; ?>/front/images/icon_date.png" /><input id="datepicker" name="News[start_date]" type="text" placeHolder="Ngày-Tháng-Năm" />
					</p>
					<label>Mô tả chuyến đi và hàng hóa có thể nhận</label>
					<p><textarea rows="4" cols="37" name="News[description]"></textarea></p>
					<p class="one_column"><input type="submit" value="Đăng tin" /></p>
				</form>
			<?php endif; ?>
		</div>
	</div>
	<script type="text/javascript" src="<?php echo Yii::app()->theme->baseUrl; ?>/front/js/jquery.validate.min.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->theme->baseUrl; ?>/front/js/validation.js"></script>